package com.ffyc.cemp.services.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ffyc.cemp.dao.mapper.IMovieMapper;
import com.ffyc.cemp.domain.entity.Movie;
import com.ffyc.cemp.domain.vo.MovieChartVo;
import com.ffyc.cemp.services.service.IMovieStatistics;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class MovieStatisticsImpl implements IMovieStatistics {

    @Autowired
    private IMovieMapper movieMapper;


    @Override
    public List<MovieChartVo> statisticeMovieType() {


        List<Map<String, Object>> list = movieMapper.countMovieType();
        List<MovieChartVo> charts = new ArrayList<>();

        for (Map<String, Object> map : list) {

            String name = (String) map.get("name");

            if (name.isEmpty()) {
                name = "其它";
            }
            long value = 0;
            if (map.get("value") != null) {
                value = (long) map.get("value");
            }
            MovieChartVo vo = new MovieChartVo();
            vo.setName(name);
            vo.setValue((int) value);

            charts.add(vo);
        }
        return charts;
    }

}